/*
  Copyright 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  KimNgan Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using DOAN.DO;
/// <summary>
/// Summary description for CT_DethiDAL
/// </summary>
namespace DOAN.DAL
{

    public class CT_DethiDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public CT_DethiDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion



        #region Public Methods
        public int Insert(CT_DethiDO objCT_DethiDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spCT_Dethi_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@Madethi", SqlDbType.Int);
            Sqlparam.Value = objCT_DethiDO.Madethi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Macauhoi", SqlDbType.VarChar);
            Sqlparam.Value = objCT_DethiDO.Macauhoi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(CT_DethiDO objCT_DethiDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spCT_Dethi_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Value = objCT_DethiDO.ID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Madethi", SqlDbType.VarChar);
            Sqlparam.Value = objCT_DethiDO.Madethi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Macauhoi", SqlDbType.VarChar);
            Sqlparam.Value = objCT_DethiDO.Macauhoi;
            Sqlcomm.Parameters.Add(Sqlparam);



            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public int Delete(CT_DethiDO objCT_DethiDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spCT_Dethi_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Value = objCT_DethiDO.ID;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spCT_Dethi_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public CT_DethiDO Select(CT_DethiDO objCT_DethiDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spCT_Dethi_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Value = objCT_DethiDO.ID;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["ID"]))
                    objCT_DethiDO.ID = Convert.ToInt32(dr["ID"]);
                if (!Convert.IsDBNull(dr["Madethi"]))
                    objCT_DethiDO.Madethi = Convert.ToInt32(dr["Madethi"]);
                if (!Convert.IsDBNull(dr["Macauhoi"]))
                    objCT_DethiDO.Macauhoi = Convert.ToInt32(dr["Macauhoi"]);

            }
            return objCT_DethiDO;
        }

        public ArrayList SelectAll1()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spCT_Dethi_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrCT_DethiDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    CT_DethiDO objCT_DethiDO = new CT_DethiDO();
                    if (!Convert.IsDBNull(dr["ID"]))
                        objCT_DethiDO.ID = Convert.ToInt32(dr["ID"]);
                    if (!Convert.IsDBNull(dr["Madethi"]))
                        objCT_DethiDO.Madethi = Convert.ToInt32(dr["Madethi"]);
                    if (!Convert.IsDBNull(dr["Macauhoi"]))
                        objCT_DethiDO.Macauhoi = Convert.ToInt32(dr["Macauhoi"]);
                    arrCT_DethiDO.Add(objCT_DethiDO);
                }
            }
            return arrCT_DethiDO;
        }

        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spCT_Dethi_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }


        #endregion

    }

}
